<!DOCTYPE html>
<html lang="en">

<head>

    <!-- Basic -->
    <meta charset="UTF-8"/>

    <title>权限管理</title>

    <!-- Mobile Metas -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>

    <!-- Favicon and touch icons -->
    <link rel="shortcut icon" href="__ADMIN__/assets/ico/favicon.ico" type="image/x-icon"/>
    <link rel="apple-touch-icon" href="__ADMIN__/assets/ico/apple-touch-icon.png"/>
    <link rel="apple-touch-icon" sizes="57x57" href="__ADMIN__/assets/ico/apple-touch-icon-57x57.png"/>
    <link rel="apple-touch-icon" sizes="72x72" href="__ADMIN__/assets/ico/apple-touch-icon-72x72.png"/>
    <link rel="apple-touch-icon" sizes="76x76" href="__ADMIN__/assets/ico/apple-touch-icon-76x76.png"/>
    <link rel="apple-touch-icon" sizes="114x114" href="__ADMIN__/assets/ico/apple-touch-icon-114x114.png"/>
    <link rel="apple-touch-icon" sizes="120x120" href="__ADMIN__/assets/ico/apple-touch-icon-120x120.png"/>
    <link rel="apple-touch-icon" sizes="144x144" href="__ADMIN__/assets/ico/apple-touch-icon-144x144.png"/>
    <link rel="apple-touch-icon" sizes="152x152" href="__ADMIN__/assets/ico/apple-touch-icon-152x152.png"/>

    <!-- start: CSS file-->

    <!-- Vendor CSS-->
    <!--<link href="__ADMIN__/assets/css/pagination.css" rel="stylesheet" />-->
    <link href="__ADMIN__/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/vendor/skycons/css/skycons.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>

    <!-- Plugins CSS-->
    <link href="__ADMIN__/assets/css/toastr.min.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/plugins/bootkit/css/bootkit.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/plugins/fullcalendar/css/fullcalendar.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/plugins/jquery-ui/css/jquery-ui-1.10.4.min.css" rel="stylesheet"/>

    <!-- Theme CSS -->
    <link href="__ADMIN__/assets/css/jquery.mmenu.css" rel="stylesheet"/>

    <!-- Page CSS -->
    <link href="__ADMIN__/assets/css/style.css" rel="stylesheet"/>
    <link href="__ADMIN__/assets/css/add-ons.min.css" rel="stylesheet"/>

    <!-- end: CSS file-->

</head>

<body>

<!-- Start: Header -->
{include file="public/header"}
<!-- End: Header -->

<!-- Start: Content -->
<div class="container-fluid content">

    <div class="row">

        <!-- Sidebar -->
        {include file="public/sidebar"}
        <!-- End Sidebar -->

        <!-- Main Page -->
        <div class="main sidebar-minified">

            <!-- Page Header -->
            <div class="page-header">
                <div class="pull-left">
                    <ol class="breadcrumb visible-sm visible-md visible-lg">
                        <li><a href="index.html"><i class="icon fa fa-home"></i>后台首页</a></li>
                        <li class="active"><i class="fa fa-shield"></i>权限规则管理</li>
                    </ol>
                </div>
                <div class="pull-right">
                    <h2>权限规则列表</h2>
                </div>
            </div>
            <!-- End Page Header -->

            <!--详细信息模态框-->
            <div class="modal fade" id="detailModal" style="margin-top: 70px;" tabindex="-1" role="dialog"
                 aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="row">
                            <div class="col-md-12"
                                 style="float: none; display: block; margin-left: auto; margin-right: auto;">
                                <div class="panel-heading bk-bg-primary">
                                    <h6 id="detailTitle"><i class="fa fa-shield red"></i></h6>
                                </div>
                                <div class="panel-body">
                                    <form class="form-horizontal" style="text-align: center;">

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">ID</label>
                                            <div class="col-md-9">
                                                <p id="detail-id" class="form-control-static"></p>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">上级权限规则名称</label>
                                            <div class="col-md-9">
                                                <p id="detail-pname" class="form-control-static"></p>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">权限规则名称</label>
                                            <div class="col-md-9">
                                                <p id="detail-name" class="form-control-static"></p>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">控/方</label>
                                            <div class="col-md-9">
                                                <p id="detail-title" class="form-control-static"></p>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">级别</label>
                                            <div class="col-md-9">
                                                <p id="detail-level" class="form-control-static"></p>
                                            </div>
                                        </div>

                                    </form>
                                    <br>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--End 相信信息模态框-->

            <!--添加模态框-->
            <div class="modal fade" id="addModal" style="margin-top: 70px;" tabindex="-1" role="dialog"
                 aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="row">
                            <div class="col-md-12"
                                 style="float: none; display: block; margin-left: auto; margin-right: auto;">
                                <div class="panel-heading bk-bg-primary">
                                    <h6><i class="fa fa-shield red"></i> 添加权限规则</h6>
                                </div>
                                <div class="panel-body">
                                    <form id="addForm" action="{:url('/auth_rule')}" method="post" class="form-horizontal">

                                        <div class="form-group">
                                            <label class="col-md-3 control-label" for="pid">上级权限</label>
                                            <div class="col-md-9">
                                                <select  name="pid" id="pid" class="form-control" size="1">
                                                    <option value="0">顶级权限</option>
                                                    {volist name="rules" id="rule"}
                                                    <option value="{$rule.id}">
                                                        <?= str_repeat('|————', $rule['level']) ?>{$rule.name}
                                                    </option>
                                                    {/volist}
                                                </select>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label" for="addName">权限名称</label>
                                            <div class="col-md-9">
                                                <input type="text" id="addName" name="name" class="form-control">
                                                <span class="help-block"></span>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label" for="addTitle">控/方</label>
                                            <div class="col-md-9">
                                                <input type="text" id="addTitle" name="title" class="form-control">
                                                <span class="help-block"></span>
                                            </div>
                                        </div>

                                        <br>
                                        <div class="form-group" style="text-align: center;">
                                            <button type="submit" class="bk-margin-5 btn btn-default"> 确认保存</button>
                                        </div>

                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--End 编辑模态框-->

            <!--编辑模态框-->
            <div class="modal fade" id="editModal" style="margin-top: 70px;" tabindex="-1" role="dialog"
                 aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="row">
                            <div class="col-md-12"
                                 style="float: none; display: block; margin-left: auto; margin-right: auto;">
                                <div class="panel-heading bk-bg-primary">
                                    <h6 id="editTitle"><i class="fa fa-shield red"></i></h6>
                                </div>
                                <div class="panel-body">
                                    <form id="editForm" action="" method="post" class="form-horizontal">

                                        <input type="hidden" name="_method" value="put">

                                        <div class="form-group">
                                            <label class="col-md-3 control-label" for="pid">上级权限</label>
                                            <div class="col-md-9">
                                                <select  name="pid" id="edit-pid" class="form-control" size="1">
                                                    <option value="0">顶级权限</option>
                                                    {volist name="rules" id="rule"}
                                                    <option edit-option="edit-option" value="{$rule.id}">
                                                        <?= str_repeat('|————', $rule['level']) ?>{$rule.name}
                                                    </option>
                                                    {/volist}
                                                </select>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label" for="addName">权限名称</label>
                                            <div class="col-md-9">
                                                <input type="text" id="edit-name" name="name" class="form-control">
                                                <span class="help-block"></span>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label" for="addTitle">控/方</label>
                                            <div class="col-md-9">
                                                <input type="text" id="edit-title" name="title" class="form-control">
                                                <span class="help-block"></span>
                                            </div>
                                        </div>

                                        <br>
                                        <div class="form-group" style="text-align: center;">
                                            <button id="edit-sub-btn" type="submit" class="bk-margin-5 btn btn-default">
                                                确认修改
                                            </button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--End 编辑模态框-->

            <!--权限规则列表-->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel">
                        <div class="panel-heading bk-bg-primary">
                            <h6><i class="fa fa-shield red"></i><span class="break"></span>权限规则列表</h6>
                            <div class="panel-actions">
                                <a href="javascript:void(0)" id="addAuthRule" data-target="#addModal" data-toggle="modal"><i
                                        class="fa fa-plus"></i></a>
                            </div>
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered bootstrap-datatable datatable">
                                    <thead>
                                    <tr>
                                        <th style="text-align: center">ID</th>
                                        <th style="text-align: center">权限名</th>
                                        <th style="text-align: center">级别</th>
                                        <th style="text-align: center">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {volist name="rules" id="rule"}
                                    <tr>
                                        <td style="text-align: center; vertical-align: middle;display: table-cell;">
                                            {$rule.id}
                                        </td>
                                        <td style="text-align: left; vertical-align: middle;display: table-cell;">
                                            <?= str_repeat('|————', $rule['level']) ?>{$rule.name}
                                        </td>
                                        <td style="text-align: center; vertical-align: middle;display: table-cell;">
                                            第{$rule.level + 1}级别
                                        </td>
                                        <td style="text-align: center; vertical-align: middle;display: table-cell;">

                                            <button type="button" class="bk-margin-5 btn btn-success detail-btn"
                                                    data-target="#detailModal" data-toggle="modal"
                                                    data-id="{$rule['id']}">
                                                <i class="fa fa-search-plus"></i>
                                            </button>

                                            <button type="button" class="bk-margin-5 btn btn-info edit-btn"
                                                    data-target="#editModal" data-toggle="modal"
                                                    data-id="{$rule['id']}">
                                                <i class="fa fa-edit"></i>
                                            </button>

                                            <button type="button" class="bk-margin-5 btn btn-danger del-btn"
                                                    data-id="{$rule['id']}">
                                                <i class="fa fa-trash-o"></i>
                                            </button>

                                        </td>
                                    </tr>
                                    {/volist}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="list-page" style="text-align: center">

                    </div>
                </div>
            </div>
            <!--End 权限规则列表-->

        </div>
        <!-- End Main Page -->

    </div>

</div><!--/container-->

<div class="clearfix"></div>


<!-- start: JavaScript-->

<!-- Vendor JS-->
<script src="__ADMIN__/assets/vendor/js/jquery.min.js"></script>
<script src="__ADMIN__/assets/vendor/js/jquery-2.1.1.min.js"></script>
<script src="__ADMIN__/assets/vendor/js/jquery-migrate-1.2.1.min.js"></script>
<script src="__ADMIN__/assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="__ADMIN__/assets/vendor/skycons/js/skycons.js"></script>

<!-- Plugins JS-->
<script src="__ADMIN__/assets/js/toastr.min.js"></script>
<script src="__ADMIN__/assets/plugins/jquery-ui/js/jquery-ui-1.10.4.min.js"></script>
<script src="__ADMIN__/assets/plugins/moment/js/moment.min.js"></script>
<script src="__ADMIN__/assets/plugins/fullcalendar/js/fullcalendar.min.js"></script>

<!-- Theme JS -->
<script src="__ADMIN__/assets/js/jquery.mmenu.min.js"></script>
<script src="__ADMIN__/assets/js/core.min.js"></script>

<!-- Pages JS -->
<script src="__ADMIN__/assets/js/pages/table.js"></script>

<!-- end: JavaScript-->

<script type="text/javascript">
    $(function () {

        // 设置弹框参数
        toastr.options = {
            closeButton: true,//是否显示关闭按钮
            progressBar: true,//实现显示计时条
            timeOut: "3000",//自动关闭时间
            positionClass: "toast-top-full-width" // 顶端，宽度铺满整个屏幕
        };

        // 点击了详情按钮
        $('button.detail-btn').each(function () {
            $(this).click(function () {
                ajaxRead($(this).attr('data-id'));
            })
        });

        // 点击了编辑按钮
        $('button.edit-btn').each(function () {
            $(this).click(function () {
                ajaxEdit($(this).attr('data-id'));
            })
        });

        // 点击了删除按钮
        $('button.del-btn').each(function () {
            $(this).click(function () {
                if (confirm('你确定要 【删除】 吗?')) {
                    // 删除table的tr
                    var obj = $(this).parents('tr');
                    ajaxDel($(this).attr('data-id'), obj);
                }

            })
        });


        // ajax获取指定需要显示的用户的信息
        function ajaxRead(id) {
            $.ajax({
                type: 'get',
                data: {'id': id},
                url: '{:url("/auth_rule/' + id + '")}',
                dataType: 'json',
                success: function (rule) {
                    console.log(rule);
                    // 显示
                    $('#detail-id').html(rule.id);
                    if (rule.pname == null) {
                        $('#detail-pname').html('顶级权限');
                    } else {
                        $('#detail-pname').html(rule.pname);
                    }
                    $('#detail-name').html(rule.name);
                    $('#detail-title').html(rule.title);
                    $('#detail-level').html('第' + ( parseInt(rule.level) + 1 ) + '级权限规则');
                    $('#detailTitle').html('正在查看 【' + rule.name + '】 的详细信息')
                }
            });
        }

        // ajax获取指定需要编辑的用户的信息
        function ajaxEdit(uid) {
            $.ajax({
                type: 'get',
                data: {'id': uid},
                url: '{:url("auth_rule/' + uid + '/edit")}',
                dataType: 'json',
                success: function (rule) {

                    $("option[edit-option='edit-option'][value="+rule.pid+"]").attr('selected', 'selected')
                    $('#edit-name').val(rule.name);
                    $('#edit-title').val(rule.title);
                    $('#editTitle').html('正在修改 【' + rule.name + '】 的信息');

                    // 修改editform的action
                    $('form#editForm').attr('action', '/auth_rule/' + rule.id);

                }
            });
        }

        // ajax删除指定的用户
        function ajaxDel(id, obj) {
            $.ajax({
                type: 'delete',
                data: {'id': id},
                url: '{:url("/auth_rule/' + id + '")}',
                success: function (result) {

                    if (result == 1) {
                        toastr.success('删除权限规则成功!');
                        obj.remove();
                        history.go();
                    } else {
                        toastr.error('删除权限规则失败!');
                    }
                }
            });
        }


    })
</script>

</body>

</html>